
import 'dart:ffi';

import 'package:flutter/cupertino.dart';
import 'package:sjx/repository/model/task_status_number_model.dart';
import 'package:sjx/repository/model/user_info_model.dart';
import 'package:sjx/repository/model/user_model.dart';
import 'package:sjx/repository/sjx_api.dart';
import 'package:sjx/utils/sp_utils.dart';

class MineViewModel with ChangeNotifier {
  UserInfoModel? _userInfoModel;
  TaskStatusNumberModel? _taskStatusNumberModel;
  bool _isLoading = true;
  bool _isLoggedIn = false;

  UserInfoModel? get userInfoModel => _userInfoModel;
  TaskStatusNumberModel? get taskStatusNumberModel => _taskStatusNumberModel;
  bool get isLoading => _isLoading;
  bool get isLoggedIn => _isLoggedIn;

  Future requestUserInfo() async {
    _isLoading = false;
    final user = await SpUtils.getUserData();
    if (user == null) {
      _isLoggedIn = false;
    } else {
      _userInfoModel = await SJXApi.instance().userInfo();
      _taskStatusNumberModel = await SJXApi.instance().taskInfoNumber();
      _isLoggedIn = true;
    }
    notifyListeners();
  }
}